package com.zuipin.controller;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zuipin.entity.HotReview;
import com.zuipin.framework.annotation.Inject;
import com.zuipin.framework.annotation.Valid;
import com.zuipin.framework.annotation.Valids;
import com.zuipin.framework.result.Result;
import com.zuipin.service.IHotReviewService;
import com.zuipin.service.IProductInfoService;
import com.zuipin.util.Pagination;
import com.zuipin.vo.HotReviewDetailVo;
import com.zuipin.vo.HotReviewProVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import springfox.documentation.annotations.ApiIgnore;

@Api(value = "热评信息", description = "热评信息-zhouhuihang")
@RestController
@RequestMapping(value = "/hotReview")
public class HotReviewController {
	@Resource
	private IHotReviewService	hotReviewService;
	@Resource
	private IProductInfoService	productInfoService;
	
	private static Logger		log	= LoggerFactory.getLogger(NewsInfoController.class);
	
	@RequestMapping(value = "/searchHotReviewAllByBack", method = RequestMethod.GET)
	@ApiOperation(value = "分页查询热评接口（前后通用）", notes = "六期-分页查询热评接口（前后通用）-zhouhuihang")
	@Valids({ @Valid(name = "reviewStatus", regex = "1|2"), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "productSku", value = "商品编号", required = false, dataType = "string", paramType = "query"), //
			@ApiImplicitParam(name = "productName", value = "商品名称", required = false, dataType = "string", paramType = "query"), //
			@ApiImplicitParam(name = "reviewStatus", value = "状态，1:启用，2:禁用", required = false, dataType = "integer", paramType = "query"), //
			@ApiImplicitParam(name = "isUseSort", value = "是否使用排序号排序 1：是", required = false, dataType = "short", paramType = "query"), //
			@ApiImplicitParam(name = "sysId", value = "系统id", required = false, dataType = "long", paramType = "query"), //
			@ApiImplicitParam(name = "page.pageSize", value = "pageSize", required = true, dataType = "integer", paramType = "query"), //
			@ApiImplicitParam(name = "page.pageNumber", value = "pageNumber", required = true, dataType = "integer", paramType = "query"), })
	public Result<List<HotReview>> searchHotReviewAllByBack(@RequestParam(required = false) String productSku, @RequestParam(required = false) String productName,
			@RequestParam(required = false) Short isUseSort, @RequestParam(required = false) Integer reviewStatus, @RequestParam(required = false) Long sysId,
			@Inject @ApiIgnore Pagination page) {
		return hotReviewService.searchHotReviewAllByBack(productSku, productName, reviewStatus, isUseSort, sysId, page);
	}
	
	@RequestMapping(value = "/creatOrUpdateHotReview", method = RequestMethod.POST)
	@ApiOperation(value = "新建（修改）热评接口", notes = "六期-新建（修改）热评接口-zhouhuihang")
	@Valids({ @Valid(name = "HotReview.reviewer", required = true), //
			@Valid(name = "HotReview.sort", required = false, maxLength = 5), //
			@Valid(name = "HotReview.productId", required = true) })
	@ApiImplicitParams({})
	public Result creatOrUpdateHotReview(@RequestBody @ApiParam HotReview HotReview) {
		if (HotReview.getId() == null) {
			return hotReviewService.creatHotReview(HotReview);
		} else {
			return hotReviewService.updateHotReview(HotReview);
		}
	}
	
	@RequestMapping(value = "/findHotReviewDetail", method = RequestMethod.GET)
	@ApiOperation(value = "查询热评详情接口", notes = "六期-查询热评详情接口-zhouhuihang")
	@Valids({ @Valid(name = "id", required = true), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "热评ID", required = true, dataType = "long", paramType = "query"), })
	public Result<HotReviewDetailVo> findHotReviewDetail(Long id) {
		return hotReviewService.findHotReviewDetail(id);
	}
	
	@RequestMapping(value = "/modifyHotReviewStatus", method = RequestMethod.POST)
	@ApiOperation(value = "禁用|启用热评", notes = "禁用|启用热评-zhouhuihang")
	@Valids({ @Valid(name = "id", required = true), @Valid(name = "reviewStatus", required = true, regex = "1|2"), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "热评ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "reviewStatus", value = "状态状态，1:启用，2:禁用", required = true, dataType = "long", paramType = "query"), })
	public Result modifyHotReviewStatus(Long id, Integer reviewStatus) {
		return hotReviewService.modifyHotReviewStatus(id, reviewStatus);
	}
	
	@RequestMapping(value = "/getHotReviewPro", method = RequestMethod.GET)
	@ApiOperation(value = "查询热评商品基本信息", notes = "查询热评商品基本信息-zhouhuihang")
	@Valids({ @Valid(name = "productSku", required = true), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "productSku", value = "商品编号", required = true, dataType = "string", paramType = "query"), })
	public Result<HotReviewProVo> getHotReviewPro(String productSku) {
		return hotReviewService.getHotReviewPro(productSku);
	}
	
}
